﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp.Aspects;

namespace EBookStore.AOP
{
    [Serializable]
    class TraceAttribute:OnMethodBoundaryAspect
    {
        // This method is before target methods.
        public override void OnEntry(MethodExecutionArgs args)
        {

            Arguments a = args.Arguments;

            System.Diagnostics.Trace.WriteLine(string.Format(
                "[{0}] Entering [{1}-{2}]",
                DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss.fff"),
                args.Method.DeclaringType.FullName,
                args.Method.Name));
            System.Diagnostics.Trace.Indent();
            
        }

        // This method is after target methods exit with success.
        public override void OnExit(
            MethodExecutionArgs args)
        {
            System.Diagnostics.Trace.Unindent();
            System.Diagnostics.Trace.WriteLine(
                string.Format(
                "[{0}] Leaving [{1}-{2}]",
                DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss.fff"),
                args.Method.DeclaringType.FullName,
                args.Method.Name));
        }      
    }
}
